package api.rowan.dubbocontroller2.controller;

import api.rowan.pojo.Pet;
import api.rowan.pojo.Query;
import api.rowan.service.PetService;
import io.swagger.annotations.*;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

@Api(value = "Pet",tags={"宠物模块"})
@RestController
public class PetController {

    @DubboReference(check = false,mock = "api.rowan.service.PetServiceMock")
    private PetService petService;


    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = Pet.class)
    })
    @ApiOperation(value = "获取默认宠物")
    @GetMapping("/default-pet")
    public Pet getDefault(Query query){
        System.out.println(query);
        Pet pet = petService.getPet();
        pet.setBorn(query.getDate());
        return pet;
    }

    @ApiResponses({
            @ApiResponse(code = 200, message = "success", response = Pet.class)
    })
    @ApiOperation(value = "宠物mock")
    @GetMapping("/pet-mock")
    public Pet petMock(Query query){
        Pet mock = new Pet();
        mock.setName("Tom-mock");
        mock.setType("猫-mock");
        mock.setBorn(new Date());
        return mock;
    }


}
